/*******************************************************************************
 * Copyright 2017 Bstek
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.  You may obtain a copy
 * of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations under
 * the License.
 ******************************************************************************/
package com.bstek.ureport.console;

import com.bstek.ureport.Utils;
import com.bstek.ureport.console.designer.RsaUtils;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.log.NullLogChute;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;


/**
 * @author Jacky.gao
 * @since 2016年6月6日
 */
public abstract class RenderPageServletAction extends WriteJsonServletAction implements ApplicationContextAware {
    //私钥用于数据解密
    protected static String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALSukhwTBUvFxDTxjZu62bYrbOq94Mcub1mh5s+LHFxDhO6JeIo1V9K+IQte3aZoKGLUWrGyDJ3HwQ+cN9QHzhuiYt0lRsX1NMeSGqAb3IbhUxNlZD0uklohriWtJgQtyhlYUZ7okh9AOJ6sY92R9amb3zZqFPTNVveErfjUjnB7AgMBAAECgYBQZ6lctfgy3pjwiJggd7e/0jZfhk0bxmXGCP7qWDkwM9nZvzJ1qsRg47xXz4kqrwpd5KtRjW8A3e5j0Hylri2BLQ+NDGdy6LxRCpMsr534LVJG4zyr58HlDDRS40UnbomG2anJNupBRSRbRb3oRvOtHOkcDvZgA/5tbBx0C8HGuQJBAPDP2knUdKrDpNEQpTiZBKId3na6RdpWbn5RfzNUHDJSLD9gfLcz2VkGMW3FPiQyE2dzQFZ0eApwzswXEz5bnrkCQQDAE9wFL1uXBHbXhprY6u8RKzCA9oHbP0DbQpIWruPI6uGTLQjIpAGyN602QLe+lyGK8Ce0p/h6ChrY78wFAI7TAkBlc4vJMuJ71rSnB1Y0A/M5wU+pwUwQcf1W5kqqezLt2ESf5qxkGknlAYDtd/14DkiyepGOWr7/1wqoXMhUqxCxAkAevE7NyZk3XjCCJnjq0xU0Qxv81vVKlyGStGFaHdw3T1aPTXqFWLEoyn3+G3cLmXV1nR5Naz94j9th8WVNO5yfAkEAqCBAqdmeQKT60FJe0wdPxXN3x8H2aAiWp4i/kpdcMNDSM2IGAmzjfhWLu3SEFPw6o86XTVHBhIdlr9pdb2bJoQ==";


    protected VelocityEngine ve;
    protected ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
        ve = new VelocityEngine();
        ve.setProperty(Velocity.RESOURCE_LOADER, "class");
        ve.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        ve.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new NullLogChute());
        ve.init();
    }

    protected String getDecryptMethod(String encryptText) {
        String decryptText = "";
        try {
            if (encryptText != null) {
                String[] split = encryptText.split(",");
                for (String cipherSql : split) {
                    // 处理每个参数值
                    decryptText = decryptText + RsaUtils.decrypt(cipherSql, privateKey);
                }
            }
        } catch (Exception e) {
            Utils.logToConsole("b解密SQL字符串分割列表异常:" + e.getMessage());
        }
		return decryptText;
    }
}
